package com.yc.blog.springboot.event.demo1;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * 学生监听多种事件，并作出响应
 */
@Component
public class Student {

	/**
	 * 监听上课铃声
	 * @param event1
	 */
	@EventListener
	public void listenSchoolBell(SchoolBellEvent event) {
		System.out.println("上课铃响了，我要去上课...");
		//do something
	}
	
	/**
	 * 监听老师提问
	 * @param event2
	 */
	@EventListener
	public void listenTeacherAskMe(TeacherAskEvent event) {
		System.out.println("老师提问了，我要起立回答问题...");
		//do something
	}
	
}
//上课铃声事件
class SchoolBellEvent extends ApplicationEvent {

	public SchoolBellEvent(Object source) {
		super(source);
	}
	
}

//老师提问事件
class TeacherAskEvent extends ApplicationEvent {

	public TeacherAskEvent(Object source) {
		super(source);
		// TODO Auto-generated constructor stub
	}
	
}